package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.ClientRegisterEvent;
	import net.optix.ip.model.ModelLocator;

	public class ClientRegisterCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:ClientRegisterEvent = ClientRegisterEvent( event );
			var delegate:UserDelegate = new UserDelegate();     
			delegate.clientRegister( this , myEvent.vo);
			model.result	=	"Registering Business ...";
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			trace(event.result);
			try
			{
				var result:int	=	event.result.result;
				switch(result)
				{
					case -1:
						model.result	=	"The email is used,try other";
						break;
					case 1:
						model.result	=	"Successfully Registered Business !";
						model.close		=	"no";
						model.close		=	"yes";
						break;	
					case 0:
						model.result	=	"Program error";
						break;
				}
				
			}
			catch(error:Error)
			{
				model.result	=	"There are some error in program or sending email !";
			}
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			
			model.result	=	"Program error";
			model.bSubmit	=	true;
		}

	}
}